using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using NUnit.Framework;

namespace Entities
{
    [TestFixture]
    public class ArtistFixture:ConnectionFixture
    {
        private static readonly string artistName = "Artist";
        private ArtistGateway gateway;
        private RecordingDataSet recordingDataSet;
        private long insertedId;


        [SetUp]
        public void SetUp()
        {
            gateway = new ArtistGateway(Connection);
            recordingDataSet = new RecordingDataSet();
            insertedId = gateway.Insert(artistName, recordingDataSet);

        }

        [TearDown]
        public void TearDown()
        {
            gateway.Delete(insertedId, recordingDataSet);
        }


        [Test]
        public void Retrive()
        {
            RecordingDataSet loadedFromDB = new RecordingDataSet();
            RecordingDataSet.ArtistRow loadedFromDBArtist = gateway.FindById(insertedId, loadedFromDB);

            Assert.AreEqual(insertedId, loadedFromDBArtist.id);
            Assert.AreEqual(artistName, loadedFromDBArtist.name);
        }

        [Test]
        public void Delete()
        {
            RecordingDataSet emptyDataSet = new RecordingDataSet();
            long deletedId = gateway.Insert("Deleted Artist", emptyDataSet);

            gateway.Delete(deletedId, emptyDataSet);
            Assert.IsNull(gateway.FindById(deletedId, emptyDataSet));
        }

        [Test]
        public void Update()
        {
            RecordingDataSet.ArtistRow row = gateway.FindById(insertedId, recordingDataSet);
            row.name = "Modified Name";
            gateway.Update(recordingDataSet);

            string updatedName = gateway.FindById(insertedId, new RecordingDataSet()).name;
            Assert.AreEqual("Modified Name", updatedName);

            
        }
    }
}
